<?php
namespace app\admin\controller;

use think\Controller;
use think\Loader;
use think\Session;

class Admin extends Controller
{
    public function _initialize()
    {
        // 判断是否登录，没有登录跳转登录页面
        if (!Session::get('user_auth') || !Session::get('user_auth_sign')) {
            $this->redirect('Login/index');
        }

        //权限检测 过滤超级管理员uid:1
        $uid = Session::get('user_auth')['uid'];
        if ($uid != 1) {
            //当前请求URL的pathinfo信息(不含URL后缀)
            $rule = strtolower($this->request->module())
                . "/" . strtolower($this->request->controller())
                . "/" . strtolower($this->request->action());
            //不需要检测的模块/控制器/方法
            $not_check = [
                'admin/index/index',
                'admin/index/welcome'
            ];
            if (!in_array($rule, $not_check)) {
                $auth = \Auth::instance();
                if (!$auth->check($rule, $uid)) {
                    $this->error('抱歉，您没有操作权限', 'Index/index');
                }
            }
        }
    }
}